| *Keyword*              |                                 |                                |                                   |                                             |                           |                               |
| Create source          | [Documentation]                 | Create a source                |                                   |                                             |                           |                               |
|                        | [Arguments]                     | ${name}=${DEFAULT_SOURCE}      | ${url}=${RULES_URL}               | ${file}=${RULES_SINGLE_FILE}                | ${method}=${RULES_METHOD} | ${datatype}=${RULES_DATATYPE} |
|                        | SN Go To                        | ${BASE_URL}rules/source/add    |                                   |                                             |                           |                               |
|                        | Input Text                      | id_name                        | ${name}                           |                                             |                           |                               |
|                        | Select From List                | id_datatype                    | ${datatype}                       |                                             |                           |                               |
|                        | Run Keyword If                  | '${method}' == 'file'          | _Set file source                  | file=${file}                                |                           |                               |
|                        | Run Keyword If                  | '${method}' == 'url'           | _Set url source                   | url=${url}                                  |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | SN Click Element                | xpath=//button[@type='submit'] |                                   |                                             |                           |                               |
|                        | Page Should Not Contain Element | xpath=//button[@type='submit'] |                                   |                                             |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | _Wait for source                | Source updated                 | Error during source update        |                                             |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | Element Should Not Contain      | id=init_details                | Error during source update        |                                             |                           |                               |
|                        | _Wait for source                | Source is valid                | Source test failure               |                                             |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | ${ret}=                         | Run Keyword And Return Status  | Page should Contain Element       | xpath=//button[@type='continue']            |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | Run Keyword If                  | ${ret} == True                 | SN Click Element                  | xpath=//button[@type='continue']            |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | SN Go To                        | ${BASE_URL}rules/source/       |                                   |                                             |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | Page Should Contain             | ${name}                        |                                   |                                             |                           |                               |
| _Wait for source       | [Documentation]                 | Wait                           |                                   |                                             |                           |                               |
|                        | [Arguments]                     | @{vals}                        |                                   |                                             |                           |                               |
|                        | :FOR                            | ${i}                           | IN RANGE                          | 240                                         |                           |                               |
|                        | \                               | ${ret}=                        | Run Keyword                       | _Check source validity                      | @{vals}                   |                               |
|                        | \                               | Return From Keyword If         | ${ret} == True                    | True                                        |                           |                               |
|                        | \                               | Sleep                          | 1s                                |                                             |                           |                               |
|                        | Return From Keyword             | False                          |                                   |                                             |                           |                               |
| _Check source validity | [Documentation]                 |                                |                                   |                                             |                           |                               |
|                        | [Arguments]                     | @{vals}                        |                                   |                                             |                           |                               |
|                        | :FOR                            | ${text}                        | IN                                | @{vals}                                     |                           |                               |
|                        | \                               | ${ret}=                        | Run Keyword And Return Status     | Element should contain                      | id=init_details           | ${text}                       |
|                        | \                               | Return From Keyword If         | ${ret} == True                    | True                                        |                           |                               |
|                        | Return From Keyword             | False                          |                                   |                                             |                           |                               |
| _Set file source       |                                 |                                |                                   |                                             |                           |                               |
|                        | [Arguments]                     | ${file}                        |                                   |                                             |                           |                               |
|                        | Select From List                | id_method                      | Upload                            |                                             |                           |                               |
|                        | Wait Until Element Is Visible   | id_file                        | 30                                |                                             |                           |                               |
|                        | Choose File                     | id_file                        | ${file}                           |                                             |                           |                               |
| _Set url source        |                                 |                                |                                   |                                             |                           |                               |
|                        | [Arguments]                     | ${url}                         |                                   |                                             |                           |                               |
|                        | Select From List                | id_method                      | HTTP URL                          |                                             |                           |                               |
|                        | Wait Until Element Is Visible   | id_uri                         | 30                                |                                             |                           |                               |
|                        | Input Text                      | id_uri                         | ${url}                            |                                             |                           |                               |
| Delete source          | [Documentation]                 | Delete a source                |                                   |                                             |                           |                               |
|                        | [Arguments]                     | ${name}=${DEFAULT_SOURCE}      |                                   |                                             |                           |                               |
|                        | SN Go To                        | ${BASE_URL}rules/source/       |                                   |                                             |                           |                               |
|                        | SN Click Element                | link=${name}                   |                                   |                                             |                           |                               |
|                        | ${loc}=                         | Get Location                   |                                   |                                             |                           |                               |
|                        | ${prefix}=                      | Regexp Escape                  | ${BASE_URL}                       |                                             |                           |                               |
|                        | Should Match Regexp             | ${loc}                         | ${prefix}rules\\/source\\/\\d+\\/ |                                             |                           |                               |
|                        | ${prefix}=                      | Regexp Escape                  | ${loc}                            |                                             |                           |                               |
|                        | SN Click Element                | link=Delete                    |                                   |                                             |                           |                               |
|                        | ${loc}=                         | Get Location                   |                                   |                                             |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | Should Match Regexp             | ${loc}                         | ${prefix}delete                   |                                             |                           |                               |
|                        | SN Click Element                | xpath=//button[@type='submit'] |                                   |                                             |                           |                               |
|                        | Debug Screenshot                |                                |                                   |                                             |                           |                               |
|                        | Page Should Contain             | Copyright                      |                                   |                                             |                           |                               |
|                        | Page Should Not Contain         | ${name}                        |                                   |                                             |                           |                               |
| Test source            | [Documentation]                 | Create a source and delete it  |                                   |                                             |                           |                               |
|                        | [Arguments]                     | ${name}=${DEFAULT_SOURCE}      | ${url}=${RULES_URL}               | ${file}=${RULES_SINGLE_FILE}                | ${method}=${RULES_METHOD} | ${datatype}=${RULES_DATATYPE} |
|                        | Create source                   | name=${name}                   | url=${url}                        | file=${file}                                | method=${method}          | datatype=${datatype}          |
|                        | Delete source                   | name=${name}                   |                                   |                                             |                           |                               |
| Clean sources          | [Documentation]                 | Remove all sources             |                                   |                                             |                           |                               |
|                        | :FOR                            | ${i}                           | IN RANGE                          | 64                                          |                           |                               |
|                        | \                               | SN Go To                       | ${BASE_URL}rules/source/          |                                             |                           |                               |
|                        | \                               | ${no_object}=                  | Run Keyword And Return Status     | Page Should Contain                         | No object available.      |                               |
|                        | \                               | Return From Keyword If         | ${no_object} == 1                 |                                             |                           |                               |
|                        | \                               | ${name}=                       | Get Table Cell                    | xpath=//div[@class='table-container']/table | 2                         | 1                             |
|                        | \                               | Log                            | ${name}                           |                                             |                           |                               |
|                        | \                               | Delete Source                  | name=${name}                      |                                             |                           |                               |
